require 'sqlite3_db'

def find_by_name(db, name, iden)
  conditions = "`japaness_name` like \"#{name}\""
  dbs = db.find(:all, :conditions=>conditions)
  unless dbs.empty?
    dbs.each do |one|
      return one if one.japaness_name == name
    end
  end
  raise "#{iden} #{name} not found"
end

def find_item_by_name(name)
  return find_by_name(Item, name, "item")
end

def find_monster_type_by_name(name)
  return find_by_name(MonsterType, name, "monster_type")
end

def find_map_by_name(name)
  return find_by_name(Map, name, "map")
end

def find_monster_by_name(name)
  return find_by_name(Monster, name, "monster")
end

def find_town_by_name(name)
  return find_by_name(Town, name, "town")
end

def find_dungeon_by_name(name)
  return find_by_name(Dungeon, name, "dungeon")
end


